snapashot: Optimize rounded clip nodes
authorTimm Bäder <mail@baedert.org>
Fri, 1 Dec 2017 07:04:31 +0000 (08:04 +0100)
committerTimm Bäder <mail@baedert.org>
Fri, 1 Dec 2017 07:14:01 +0000 (08:14 +0100)
If the rounded clip node is rectilinear, we can simplify it to a normal
clip node. If not, we really need to use a rounded clip node. In both
cases, we can do the same check we do when collecting normal clips and
avoid the clip node altogether if the child node does not get clipped
anyway.

This saves between 3 and 10 nodes in the widget factory, depending on
what page gets rendered.

gtk/gtksnapshot.c

index c969fdece63f21781d9aa3de0bb8903dedd7c6b4..a5d4c3968d1e47f3cd094fac08178f52f7e07446 100644 (file)
@@ -636,7 +636,23 @@ gtk_snapshot_collect_rounded_clip (GtkSnapshot      *snapshot,
   if (node == NULL)
     return NULL;
 
-  clip_node = gsk_rounded_clip_node_new (node, &state->data.rounded_clip.bounds);
+  /* If the given radius is 0 in all corners, we can just create a normal clip node */
+  if (gsk_rounded_rect_is_rectilinear (&state->data.rounded_clip.bounds))
+    {
+      /* ... and do the same optimization */
+      if (graphene_rect_contains_rect (&state->data.rounded_clip.bounds.bounds, &node->bounds))
+        return node;
+
+      clip_node = gsk_clip_node_new (node, &state->data.rounded_clip.bounds.bounds);
+    }
+  else
+    {
+      if (gsk_rounded_rect_contains_rect (&state->data.rounded_clip.bounds, &node->bounds))
+        return node;
+
+      clip_node = gsk_rounded_clip_node_new (node, &state->data.rounded_clip.bounds);
+    }
+
   if (name)
     gsk_render_node_set_name (clip_node, name);